import { defineStore } from "pinia";
import { reqEchartsData } from "@/api/echarts";
import { ElMessage } from "element-plus";
import type{EchartsData} from '@/api/echarts'

type EchartsStoreData = {
  echartsData:EchartsData
}
export const useEchartsStore = defineStore("echarts", {
  state: ():EchartsStoreData => {
    return {
      // 初始化
      echartsData: {
        salesToday: 0,
        salesLastDay: 0,
        salesGrowthLastDay: 0,
        salesGrowthLastMonth: 0,
      
        orderToday: 0,
        orderLastDay: 0,
        orderTrend: [],
        orderTrendAxis: [],
      
        orderUser: 0,
        returnRate: 0,
        orderUserTrend: [],
        orderUserTrendAxis: [],
      
        usersTotal: 0,
        usersLastDay: 0,
        usersLastMonth: 0,
        userGrowthLastDay: '',
        userGrowthLastMonth: '',
      
        orderFullYearAxis: [],
        orderFullYear: [],
        userFullYearAxis: [],
        userFullYear: [],
      
        orderRank: [],
        userRank: [],
      
        searchWord: [],
        saleRank: {
          category: {
            axisX: [],
            data1: [],
          },
          goods: {
            axisX: [],
            data1: [],
          }
        }
      },
    };
  },
  actions: {
    async getEchartsData() {
      try {
        const res = await reqEchartsData();
        this.echartsData = res;
      } catch (error) {
        ElMessage.error('获取图表数据失败')
      }
    },
  },
  getters: {},
});
